package com.xueyi.operations.controller.admin;

import com.xueyi.common.core.utils.DateUtil;
import com.xueyi.common.core.web.result.AjaxResult;
import com.xueyi.common.core.web.validate.V_A;
import com.xueyi.common.core.web.validate.V_E;
import com.xueyi.common.log.annotation.Log;
import com.xueyi.common.log.enums.BusinessType;
import com.xueyi.operations.domain.po.OpMakerInfoPo;
import io.swagger.v3.oas.annotations.OpenAPI31;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import com.xueyi.operations.controller.base.BOpMakerInfoController;
import com.xueyi.operations.domain.dto.OpMakerInfoDto;
import com.xueyi.operations.domain.query.OpMakerInfoQuery;
import io.swagger.v3.oas.annotations.Operation;
import com.xueyi.common.security.annotation.AdminAuth;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletResponse;

import java.io.Console;
import java.io.Serializable;
import java.net.http.HttpRequest;
import java.util.List;

/**
 * 厂商信息管理 | 管理端 业务处理
 *
 * @author lwb
 */
@AdminAuth
@RestController
@RequestMapping("/admin/makerinfo")
@Tag(name = "厂商信息管理 | 管理端 业务处理")
public class AOpMakerInfoController extends BOpMakerInfoController {



    @Override
    @GetMapping("/list")
    @Operation(summary = "查询厂商信息列表")
    @PreAuthorize("@ss.hasAuthority('RD:operations:makerinfo:list')")
    public AjaxResult list(OpMakerInfoQuery opMakerInfo) {
        startPage();

        if(StringUtils.isNotEmpty(opMakerInfo.getStartEstablishmentDate())){
            opMakerInfo.setStartDate(DateUtil.parseDate(opMakerInfo.getStartEstablishmentDate().substring(0,10)));
        }

        if(StringUtils.isNotEmpty(opMakerInfo.getEndEstablishmentDate())){
            opMakerInfo.setEndDate(DateUtil.parseDate(opMakerInfo.getEndEstablishmentDate().substring(0,10) + " 23:59:59"));
        }

        List<OpMakerInfoPo> list = super.baseService.selectMyList(opMakerInfo);
        return getDataTable(list);
    }

    @Override
    @GetMapping(value = "/{id}")
    @Operation(summary = "查询厂商信息详细")
    @PreAuthorize("@ss.hasAuthority('RD:operations:makerinfo:single')")
    public AjaxResult getInfo(@PathVariable Serializable id) {
        return super.getInfo(id);
    }

    @Override
    @PostMapping("/export")
    @Operation(summary = "厂商信息导出")
    @PreAuthorize("@ss.hasAuthority('RD:operations:makerinfo:export')")
    @Log(title = "厂商信息管理", businessType = BusinessType.EXPORT)
    public void export(HttpServletResponse response, OpMakerInfoQuery opMakerInfo) {

        super.export(response, opMakerInfo);
    }

    @Override
    @PostMapping
    @Operation(summary = "厂商信息新增")
    @PreAuthorize("@ss.hasAuthority('RD:operations:makerinfo:add')")
    @Log(title = "厂商信息管理", businessType = BusinessType.INSERT)
    public AjaxResult add(@Validated({V_A.class}) @RequestBody OpMakerInfoDto opMakerInfo) {
        return super.add(opMakerInfo);
    }

    @Override
    @PutMapping
    @Operation(summary = "厂商信息修改")
    @PreAuthorize("@ss.hasAuthority('RD:operations:makerinfo:edit')")
    @Log(title = "厂商信息管理", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@Validated({V_E.class}) @RequestBody OpMakerInfoDto opMakerInfo) {
        return super.edit(opMakerInfo);
    }

    @Override
    @DeleteMapping("/batch/{idList}")
    @Operation(summary = "厂商信息批量删除")
    @PreAuthorize("@ss.hasAuthority('RD:operations:makerinfo:del')")
    @Log(title = "厂商信息管理", businessType = BusinessType.DELETE)
    public AjaxResult batchRemove(@PathVariable List<Long> idList) {
        return super.batchRemove(idList);
    }
}
